import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import viteLegacyPlugin from '@vitejs/plugin-legacy'


export default defineConfig(() => {

  return {
    plugins: [
      vue(),
      viteLegacyPlugin({
        target: ['chrome 52'],
        additionalLegacyPolyfills: ['regenerator-runtime/runtime']
      })
    ],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url))
      }
    },
    server: {
      open: true, // 自动打开
      // port: 5173, // 请求的端口号
      proxy: {
        // 代理，让本地请求到网络数据
        '/api': {
          target: 'https://newdev1.cretechsh.cn',
          changeOrigin: true,
          secure: false,
          rewrite: (path) => {
            return path.replace(/^\/api/, '')
          }
        },
        '/cretechsh': {
          target: 'https://calcapi.cretechsh.cn',
          changeOrigin: true,
          secure: false,
          rewrite: (path) => {
            return path.replace(/^\/cretechsh/, '')

          }
        }
      }
    }
  }
})
